"""
Author        yongfa
Date          2022-07-18 15:00:54
LastEditTime  2022-07-18 15:02:27
LastEditors   yongfa
Description   数据模型
"""

from app.extensions.sqlalchemy import db, EntityModel as Base


class Files(Base):

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(255), comment='文件原名')
    filename = db.Column(db.String(255), comment='文件保存名')
    file_type = db.Column(db.String(32), nullable=False, comment='文件类型')
    file_size = db.Column(db.Float, nullable=False, comment='文件尺寸')
    file_path = db.Column(db.String(255), nullable=False, comment='文件路径')
    file_small_path = db.Column(db.String(255), comment='图片缩略图')
    file_cate = db.Column(db.String(100), comment='文件分类')

    def to_dict(self, output_fields=(), exclude_fields=()):
        res = super().to_dict(output_fields=output_fields, exclude_fields=exclude_fields)

        file_fields = ['file_path', 'file_small_path']
        res.update(self.get_loc_file_url(file_fields))
        return res

    def list_to_dict(self, *args, **kwargs):
        res = self.to_dict(*args, **kwargs)
        return res
